package com.basics.post.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.basics.api.response.channel.ChannelPostListData;
import com.basics.api.response.channel.PostOrMsgData;
import com.basics.post.entity.CyChannelPost;
import com.basics.post.mapper.CyChannelPostMapper;
import com.basics.post.service.CyChannelPostService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 频道帖子 服务实现类
 * </p>
 *
 * @author WangWei
 * @since 2025-03-09
 */
@Service
public class CyChannelPostServiceImpl extends ServiceImpl<CyChannelPostMapper, CyChannelPost> implements CyChannelPostService {

    @Override
    public PostOrMsgData getLastPost(Long channelId){
        return this.baseMapper.getLastPost(channelId);
    }

    @Override
    public IPage<ChannelPostListData> selectChannelPostList(Page page, Long channelId, Long userId,String topicId){
        return this.baseMapper.selectChannelPostList(page,channelId,userId,topicId);
    }

    @Override
    public  int getPostNumByUserId(Long userId,Long organizationId){
        return count(new QueryWrapper<CyChannelPost>().eq("user_id",userId)
                .eq("organization_id",organizationId).eq("del_flag",0));
    }
}
